#include <buola/scene/techniques/cskintechnique.h>
#include <buola/scene/crendercontext.h>

#include "shaders/sSkinningShader.h"
#include "shaders/sTextureShader.h"

namespace buola { namespace scene {

CSkinTechnique::CSkinTechnique()
{
    mProgram.CreateAndAttach(shaders::sSkinningShader,shaders::sTextureShader);
    mProgram.BindFragmentData(0,"oFragColor");
    mProgram.BindAttribLocation(0,"iVertex");
    mProgram.BindAttribLocation(1,"iColor");
    mProgram.BindAttribLocation(2,"iNormal");
    mProgram.Link();

    uMVMatrix=mProgram.GetUniform("uMVMatrix");
    uMVPMatrix=mProgram.GetUniform("uMVPMatrix");
    uSkinMatrices=mProgram.GetUniform("uSkinMatrices");
}

CSkinTechnique::~CSkinTechnique()
{
    
}

void CSkinTechnique::Prepare(CRenderContext &pContext)
{
    if(pContext.mTechnique!=this)
    {
        mProgram.Use();
        pContext.mTechnique=this;
    //    mProgram.GetUniform("uPMatrix").SetValue(lProjection);
    //    mProgram.GetUniform("uBoneInspect").SetValue(0);
    //    gl::CUniform uTexture=mProgram.GetUniform("uTexture");
    //    uTexture.SetValue(0);
/*
        SFillMatricesContext lFMContext;
    lFMContext.mViewMatrix=pContext.mViewMatrix;
    mRoot->FillMatrices(lFMContext);

    pContext.uSkinMatrices.SetValue(lFMContext.mMatrices);
    
    pContext.mModelMatrix=mat::identity_3d();
*/

    }

    //this sets the color to a reasonable value!!! (temporary solution)
    glVertexAttrib3d(1,0.5,0.5,0.5);
//    uTransformation.SetValue(pContext.mProjectionMatrix*pContext.mViewMatrix*pContext.mModelMatrix);
}

CSkinTechnique *CSkinTechnique::Get()
{
    static CSkinTechnique *lTechnique=new CSkinTechnique;
    return lTechnique;
}

/*namespace scene*/ } /*namespace buola*/ }